import java.util.Arrays;

/**
 * @Author wonghiu
 * @Date 2021/8/19 21:17
 * @Version 1.0.1
 */
public class SortCheck {
    public static void main(String[] args) {
        int[] nums = new int[]{1,4,6,4,3,1,7};
        quickSort(nums,0,nums.length-1);
        System.out.println(Arrays.toString(nums));
    }

    private static void quickSort(int[] nums,int l, int r) {
        if (l>=r){return;}
        int i =l;
        int j = r;
        while(i<j){
            while (i<j && nums[l]<=nums[j]){j--;}
            while (i<j && nums[l]>=nums[i]){i++;}
            swap(nums,i,j);
        }
        swap(nums,l,i);
        quickSort(nums,i+1,r);
        quickSort(nums,l,i-1);
    }

    private static void swap(int[] nums, int i, int j) {
        int temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
    }
}
